﻿Public Class BlockNineHomeworkSectionOne
    Dim QuestionNumber As Integer
    Dim dtmTest, dtmTest2 As Date
    Dim filename As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    'Declare the Array as 10 rows and 3 columns
    Dim ArrayMax As Integer = 3 'One number past the end of actual info in array
    Dim HWQuestions(ArrayMax, 3) As String
    Dim intResponse As Integer
    Dim intQuestionCount As Integer = 0
    Dim intAnswerCount As Integer = 0
    Dim intReferenceCount As Integer = 0
    Dim intFirstRun As Integer = 1
    Dim strUser As String = "Enter Last Name"
    Dim strAnswer, strAnswer2, strAnswer3, strAnswer4, strAnswer5, _
     strAnswer6, strAnswer7, strAnswer8, strAnswer9, strAnswer10, strAnswer11, _
     strAnswer12, strAnswer13, strAnswer14, strAnswer15, strAnswer16, _
     strAnswer17, strAnswer18, strAnswer19, strAnswer20, strAnswer21, _
     strAnswer22, strAnswer23, strAnswer24, strAnswer25, strAnswer26, _
     strAnswer27, strAnswer28, strAnswer29, strAnswer30, strAnswer31 As String
    Dim Match1 As String
    Shared Property MidiParent As MainForm

    Private Sub CloseToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub BlockTwoHomeworkSectionOne_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If (System.IO.File.Exists(filename & "\Homework\Block 9\Block 9 Section 1.txt")) Then
            intResponse = MsgBox("This assignment has already been completed.  Are you sure you want to delete the current assignment and reaccomplish it?", 4, "Confirm Assignment Deletion")
            If intResponse = MsgBoxResult.Yes Then
                System.IO.File.Delete(filename & "\Homework\Block 9\Block 9 Section 1.txt")
                System.IO.File.Create(filename & "\Homework\Block 9\Block 9 Section 1.txt").Dispose()
            ElseIf intResponse = MsgBoxResult.No Then
                Me.Close()
            End If
        End If
        If (Not System.IO.File.Exists(filename & "\Homework\Block 9\Block 9 Section 1.txt")) Then
            System.IO.File.Create(filename & "\Homework\Block 9\Block 9 Section 1.txt").Dispose()
        End If
        If (Not System.IO.File.Exists(filename & "\Instructor\Block 9\Block 9 Section 1.txt")) Then
            System.IO.File.Create(filename & "\Instructor\Block 9\Block 9 Section 1.txt").Dispose()
        End If
        strUser = InputBox("Please enter last name", strUser)
        If strUser Is "" Then
            Me.Close()
        End If
        Matching2.Visible = False
        '************************************************
        '****** Questions Are Loaded Here****************
        '******* Column 1 is Questions (Preloaded)*******
        '******* Column 2 is Accepts Students Answer*****
        '******* Column 3 is Reference ******************

        HWQuestions(1, 1) = ""
        HWQuestions(1, 2) = ""
        HWQuestions(1, 3) = ""

        HWQuestions(2, 1) = ""
        HWQuestions(2, 2) = ""
        HWQuestions(2, 3) = ""

        HWQuestions(3, 1) = "Close"

        Next_Question(HWQuestions)
    End Sub

    Private Sub btnNextQuestion_Click(sender As System.Object, e As System.EventArgs) Handles btnNextQuestion.Click
        Next_Question(HWQuestions)
    End Sub
    Private Sub Clear_Display()
        txtQuestion.Clear()

    End Sub

    Public Function Next_Question(HWQuestions As String(,))

        If intQuestionCount > 0 Then
            WriteToFile()
        End If
        If btnNextQuestion.Text = "Done" Then
            Me.Close()
            OpenResults()
        End If
        intQuestionCount = intQuestionCount + 1

        If intQuestionCount = 2 Then
            btnNextQuestion.Text = "Done"
        End If
        If intQuestionCount = 1 Then
            Matching1.Visible = True
            Matching2.Visible = False
        End If
        If intQuestionCount = 2 Then
            Matching1.Visible = False
            Matching2.Visible = True
        End If
        txtQuestion.Text = HWQuestions(intQuestionCount, 1)
        txtReference.Text = HWQuestions(intReferenceCount, 3)

        Return intQuestionCount & intAnswerCount
    End Function

    Private Sub WriteToFile()
        Dim Integrity As String = (filename & "\Instructor\Block 9\Block 9 Section 1.txt")
        Dim Results As String = (filename & "\Homework\Block 9\Block 9 Section 1.txt")

        '***********Output to hidden file for Instructor Check***********
        If System.IO.File.Exists(Integrity) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Integrity, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine(lblColumnB1.Text & ": " & txtMatch1.Text)
                hiddenWriter.WriteLine(lblColumnB2.Text & ": " & txtMatch2.Text)
                hiddenWriter.WriteLine(lblColumnB3.Text & ": " & txtMatch3.Text)
                hiddenWriter.WriteLine(lblColumnB4.Text & ": " & txtMatch4.Text)
                hiddenWriter.WriteLine(lblColumnB5.Text & " : " & txtMatch5.Text)
                hiddenWriter.WriteLine(lblColumnB6.Text & " : " & txtMatch6.Text)
                hiddenWriter.WriteLine(lblColumnB7.Text & " : " & txtMatch7.Text)
                hiddenWriter.WriteLine(lblColumnB8.Text & " : " & txtMatch8.Text)
                hiddenWriter.WriteLine(lblColumnB9.Text & " : " & txtMatch9.Text)
                hiddenWriter.WriteLine(lblColumnB10.Text & " : " & txtMatch10.Text)
                hiddenWriter.WriteLine(lblColumnB11.Text & " : " & txtMatch11.Text)
                hiddenWriter.WriteLine(lblColumnB12.Text & " : " & txtMatch12.Text)
                hiddenWriter.WriteLine(lblColumnB13.Text & " : " & txtMatch13.Text)
                hiddenWriter.WriteLine(lblColumnB14.Text & " : " & txtMatch14.Text)
                hiddenWriter.WriteLine(lblColumnB15.Text & " : " & txtMatch15.Text)
                hiddenWriter.WriteLine(lblColumnB16.Text & " : " & txtMatch16.Text)
                hiddenWriter.WriteLine(lblCOlumnB17.Text & " : " & txtMatch17.Text)
                hiddenWriter.WriteLine(lblColumnB18.Text & " : " & txtMatch18.Text)
                hiddenWriter.WriteLine("Reference: " & txtReference.Text)
                hiddenWriter.WriteLine()
            End If
            If intQuestionCount = 2 Then
                hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine(lblColumnD1.Text & ": " & txtM2Q1.Text)
                hiddenWriter.WriteLine(lblColumnD2.Text & ": " & txtM2Q2.Text)
                hiddenWriter.WriteLine(lblColumnD3.Text & ": " & txtM2Q3.Text)
                hiddenWriter.WriteLine(lblColumnD4.Text & ": " & txtM2Q4.Text)
                hiddenWriter.WriteLine(lblColumnD5.Text & " : " & txtM2Q5.Text)
                hiddenWriter.WriteLine(lblColumnD6.Text & " : " & txtM2Q6.Text)
                hiddenWriter.WriteLine(lblColumnD7.Text & " : " & txtM2Q7.Text)
                hiddenWriter.WriteLine(lblColumnD8.Text & " : " & txtM2Q8.Text)
                hiddenWriter.WriteLine(lblColumnD9.Text & " : " & txtM2Q9.Text)
                hiddenWriter.WriteLine(lblColumnD10.Text & " : " & txtM2Q10.Text)
                hiddenWriter.WriteLine(lblColumnD11.Text & " : " & txtM2Q11.Text)
                hiddenWriter.WriteLine(lblColumnD12.Text & " : " & txtM2Q12.Text)
                hiddenWriter.WriteLine(lblColumnD13.Text & " : " & txtM2Q13.Text)
                hiddenWriter.WriteLine(lblColumnD14.Text & " : " & txtM2Q14.Text)
                hiddenWriter.WriteLine(lblColumnD15.Text & " : " & txtM2Q15.Text)
                hiddenWriter.WriteLine(lblColumnD16.Text & " : " & txtM2Q16.Text)
                hiddenWriter.WriteLine(vbTab + vbTab + vbTab + vbTab & txtMatch17.Text)
                hiddenWriter.WriteLine(vbTab + vbTab + vbTab + vbTab & txtMatch18.Text)
                hiddenWriter.WriteLine("Block 9 Section 1 Homework Complete")
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.Close()

            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist Integrity")
        End If

        '******Output to file for Student to review***********
        If System.IO.File.Exists(Results) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Results, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                'hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                'hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Instructions:" & txtQuestion.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine(lblColumnB1.Text & " : " & txtMatch1.Text & vbTab + vbTab + vbTab + vbTab + vbTab & lblColumnA1.Text)
                hiddenWriter.WriteLine(lblColumnB2.Text & " : " & txtMatch2.Text & vbTab + vbTab + vbTab + vbTab & lblColumnA2.Text)
                hiddenWriter.WriteLine(lblColumnB3.Text & " : " & txtMatch3.Text & vbTab + vbTab + vbTab + vbTab + vbTab & lblColumnA3.Text)
                hiddenWriter.WriteLine(lblColumnB4.Text & " : " & txtMatch4.Text & vbTab + vbTab + vbTab + vbTab + vbTab & lblColumnA4.Text)
                hiddenWriter.WriteLine(lblColumnB5.Text & " : " & txtMatch5.Text & vbTab + vbTab + vbTab + vbTab & lblColumnA5.Text)
                hiddenWriter.WriteLine(lblColumnB6.Text & " : " & txtMatch6.Text & vbTab + vbTab + vbTab + vbTab + vbTab + vbTab & lblColumnA6.Text)
                hiddenWriter.WriteLine(lblColumnB7.Text & " : " & txtMatch7.Text & vbTab + vbTab + vbTab + vbTab & lblColumnA7.Text)
                hiddenWriter.WriteLine(lblColumnB8.Text & " : " & txtMatch8.Text & vbTab + vbTab + vbTab + vbTab + vbTab & lblColumnA8.Text)
                hiddenWriter.WriteLine(lblColumnB9.Text & " : " & txtMatch9.Text & vbTab + vbTab + vbTab + vbTab & lblColumnA9.Text)
                hiddenWriter.WriteLine(lblColumnB10.Text & " : " & txtMatch10.Text & vbTab + vbTab & lblColumnA10.Text)
                hiddenWriter.WriteLine(lblColumnB11.Text & " : " & txtMatch11.Text & vbTab + vbTab + vbTab + vbTab & lblColumnA11.Text)
                hiddenWriter.WriteLine(lblColumnB12.Text & " : " & txtMatch12.Text & vbTab + vbTab + vbTab + vbTab + vbTab & lblColumnA12.Text)
                hiddenWriter.WriteLine(lblColumnB13.Text & " : " & txtMatch13.Text & vbTab + vbTab + vbTab + vbTab & lblColumnA13.Text)
                hiddenWriter.WriteLine(lblColumnB14.Text & " : " & txtMatch14.Text & vbTab + vbTab + vbTab + vbTab & lblColumnA14.Text)
                hiddenWriter.WriteLine(lblColumnB15.Text & " : " & txtMatch15.Text & vbTab + vbTab + vbTab + vbTab & lblColumnA15.Text)
                hiddenWriter.WriteLine(lblColumnB16.Text & " : " & txtMatch16.Text & vbTab + vbTab + vbTab & lblColumnA16.Text)
                hiddenWriter.WriteLine(lblCOlumnB17.Text & " : " & txtMatch17.Text)
                hiddenWriter.WriteLine(lblColumnB18.Text & " : " & txtMatch18.Text)
                'hiddenWriter.WriteLine("Reference: " & txtReference.Text)
                hiddenWriter.WriteLine()
            End If
            If intQuestionCount = 2 Then
                hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine(lblColumnD1.Text & ": " & txtM2Q1.Text & vbTab + vbTab + vbTab & lblColumnC1.Text)
                hiddenWriter.WriteLine(lblColumnD2.Text & ": " & txtM2Q2.Text & vbTab + vbTab + vbTab & lblColumnC2.Text)
                hiddenWriter.WriteLine(lblColumnD3.Text & ": " & txtM2Q3.Text & vbTab + vbTab + vbTab & lblColumnC3.Text)
                hiddenWriter.WriteLine(lblColumnD4.Text & ": " & txtM2Q4.Text & vbTab + vbTab + vbTab & lblColumnC4.Text)
                hiddenWriter.WriteLine(lblColumnD5.Text & " : " & txtM2Q5.Text & vbTab + vbTab + vbTab & lblColumnC5.Text)
                hiddenWriter.WriteLine(lblColumnD6.Text & " : " & txtM2Q6.Text & vbTab + vbTab & lblColumnC6.Text)
                hiddenWriter.WriteLine(lblColumnD7.Text & " : " & txtM2Q7.Text & vbTab + vbTab & lblColumnC7.Text)
                hiddenWriter.WriteLine(lblColumnD8.Text & " : " & txtM2Q8.Text & vbTab + vbTab + vbTab & lblColumnC8.Text)
                hiddenWriter.WriteLine(lblColumnD9.Text & " : " & txtM2Q9.Text & vbTab + vbTab & lblColumnC9.Text)
                hiddenWriter.WriteLine(lblColumnD10.Text & " : " & txtM2Q10.Text & vbTab + vbTab + vbTab & lblColumnC10.Text)
                hiddenWriter.WriteLine(lblColumnD11.Text & " : " & txtM2Q11.Text & vbTab + vbTab & lblColumnC11.Text)
                hiddenWriter.WriteLine(lblColumnD12.Text & " : " & txtM2Q12.Text & vbTab + vbTab + vbTab & lblColumnC12.Text)
                hiddenWriter.WriteLine(lblColumnD13.Text & " : " & txtM2Q13.Text & vbTab + vbTab & lblColumnC13.Text)
                hiddenWriter.WriteLine(lblColumnD14.Text & " : " & txtM2Q14.Text & vbTab + vbTab & lblColumnC14.Text)
                hiddenWriter.WriteLine(lblColumnD15.Text & " : " & txtM2Q15.Text & vbTab + vbTab & lblColumnC15.Text)
                hiddenWriter.WriteLine(lblColumnD16.Text & " : " & txtM2Q16.Text & vbTab + vbTab & lblColumnC16.Text)
                hiddenWriter.WriteLine(lblColumnD17.Text & " : " & txtM2Q17.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Block 9 Section 1 Homework Complete")
                'hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                'hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.Close()

            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist Results")
        End If
    End Sub

    Private Sub OpenResults()
        Dim p As Process = Process.Start(filename & "\Homework\Block 9\Block 9 Section 1.txt")
    End Sub
End Class
